package com.example.depcontrol.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    @Override//初始化，调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override//拦截到请求后调用，调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        //拦截请求后调用filterChain来放行，允许访问资源
        filterChain.doFilter(servletRequest, servletResponse);//注：chain的doFilter和该实现类的doFilter不是一个方法

    }

    @Override//销毁方法，只调用一次
    public void destroy() {
        Filter.super.destroy();
    }
}
